#!/usr/bin/ruby -Ku
# -*- coding: utf-8 -*-
require 'test/unit'
require 'm3g'

class Test_Appearance < Test::Unit::TestCase
  def setup
  end

  def teadown
  end

  def test_default_variables
    app = M3G::Appearance.new
    
    # 仕様上は順番は未定義
    assert_equal 0  , app.layer
    assert_equal nil, app.polygon_mode
    assert_equal nil, app.compositing_mode
    assert_equal nil, app.texture[0]
    assert_equal nil, app.texture[1]
    assert_equal nil, app.texture[2]
    assert_equal nil, app.texture[3]
    assert_equal nil, app.material
    assert_equal nil, app.fog
  end

  def test_set_variables
    app   = M3G::Appearance.new
    cmode = M3G::CompositingMode.new
    pmode = M3G::PolygonMode.new
    fog   = M3G::Fog.new
    mat   = M3G::Material.new
    img   = M3G::Image2D.new M3G::Image2D::RGBA, 64, 64
    tex0  = M3G::Texture2D.new img
    tex1  = M3G::Texture2D.new img
    tex2  = M3G::Texture2D.new img
    tex3  = M3G::Texture2D.new img

    app.compositing_mode = cmode
    app.polygon_mode     = pmode
    app.fog              = fog
    app.layer            = 1
    app.material         = mat
    app.texture[0]       = tex0
    app.texture[1]       = tex1
    app.texture[2]       = tex2
    app.texture[3]       = tex3

    assert_equal 1    , app.layer
    assert_equal pmode, app.polygon_mode
    assert_equal cmode, app.compositing_mode
    assert_equal tex0 , app.texture[0]
    assert_equal tex1 , app.texture[1]
    assert_equal tex2 , app.texture[2]
    assert_equal tex3 , app.texture[3]
    assert_equal mat  , app.material
    assert_equal fog  , app.fog
  end

  def test_duplicate
    app1  = M3G::Appearance.new
    cmode = M3G::CompositingMode.new
    pmode = M3G::PolygonMode.new
    fog   = M3G::Fog.new
    mat   = M3G::Material.new
    img   = M3G::Image2D.new M3G::Image2D::RGBA, 64, 64
    tex0  = M3G::Texture2D.new img
    tex1  = M3G::Texture2D.new img
    tex2  = M3G::Texture2D.new img
    tex3  = M3G::Texture2D.new img

    app1.compositing_mode = cmode
    app1.polygon_mode     = pmode
    app1.fog              = fog
    app1.layer            = 1
    app1.material         = mat
    app1.texture[0]       = tex0
    app1.texture[1]       = tex1
    app1.texture[2]       = tex2
    app1.texture[3]       = tex3

    app2 = app1.duplicate

    assert_not_equal app1 , app2
    assert_equal     1    , app2.layer
    assert_equal     pmode, app2.polygon_mode
    assert_equal     cmode, app2.compositing_mode
    assert_equal     tex0 , app2.texture[0]
    assert_equal     tex1 , app2.texture[1]
    assert_equal     tex2 , app2.texture[2]
    assert_equal     tex3 , app2.texture[3]
    assert_equal     mat  , app2.material
    assert_equal     fog  , app2.fog
  end

  def test_references
    app   = M3G::Appearance.new
    cmode = M3G::CompositingMode.new
    pmode = M3G::PolygonMode.new
    fog   = M3G::Fog.new
    mat   = M3G::Material.new
    img   = M3G::Image2D.new M3G::Image2D::RGBA, 64, 64
    tex0  = M3G::Texture2D.new img
    tex1  = M3G::Texture2D.new img
    tex2  = M3G::Texture2D.new img
    tex3  = M3G::Texture2D.new img

    app.compositing_mode = cmode
    app.polygon_mode     = pmode
    app.fog              = fog
    app.layer            = 1
    app.material         = mat
    app.texture[0]       = tex0
    app.texture[1]       = tex1
    app.texture[2]       = tex2
    app.texture[3]       = tex3

    objs = app.references

    assert_equal 8    , objs.length
    assert_equal pmode, objs[0]
    assert_equal cmode, objs[1]
    assert_equal mat  , objs[2]
    assert_equal tex0 , objs[3]
    assert_equal tex1 , objs[4]
    assert_equal tex2 , objs[5]
    assert_equal tex3 , objs[6]
    assert_equal fog  , objs[7]
  end

end
